import {
  GOODS,
  GOODS_COLUMNS,
  Customer,
  transaction,
  Withdrawal,
  WithdrawalMoney,
  userData,
  postData,
  postTel,
  bankData,
  getOrder,
  getCount,
  getMember,
  frozen,
  deny,
  updateCertificate,
  createMember,
  getDisNo,
  disGetList,
  getHistogram,
  upload,
  getUpload,
  updatePassWord,
  getInviteMembers,
  forgetPassword,
  createDis,
  GetTreeData,
  ApplyCashOut,
  ApplyHistory,
  delApplyHistory,
} from "./api";
import { METHOD, request } from "@/utils/request";
import { requestUp } from "../utils/request1";

const BASE_URL =
  process.env.NODE_ENV === "production"
    ? "http://124.71.234.61:21021"
    : "http://124.71.234.61:21021";
export async function goodsList(params) {
  return request(GOODS, METHOD.GET, params);
}

export async function goodsColumns() {
  return request(GOODS_COLUMNS, METHOD.GET);
}
export async function getCustomer(_page, _size) {
  return request(Customer, METHOD.GET, {
    _page: _page,
    _size: _size,
  });
}
export async function addCustomerData(
  cAddress,
  cContact,
  cGroup,
  cName,
  cPhone,
  eMailAddress
) {
  return request(Customer, METHOD.GET, {
    cAddress: cAddress,
    cContact: cContact,
    cGroup: cGroup,
    cName: cName,
    cPhone: cPhone,
    eMailAddress: eMailAddress,
  });
}
// 获取交易数据
export async function getTransaction(disNo, skipCount, maxResultCount) {
  return request(transaction, METHOD.GET, {
    disNo: disNo,
    skipCount: skipCount,
    maxResultCount: maxResultCount,
  });
}
// 获取提现数据 佣金查询
export async function getWithdrawal(disNo, skipCount, maxResultCount) {
  return request(Withdrawal, METHOD.GET, {
    disNo: disNo,
    skipCount: skipCount,
    maxResultCount: maxResultCount,
  });
}
// 获取银行数据
export async function getTreeData(layout) {
  return request(GetTreeData, METHOD.GET, {
    layout,
  });
}

// 佣金提现
export async function getMoney(
  disbName,
  disbNo,
  applyUser,
  applyUserId,
  accountNum,
  tradeIds
) {
  return request(WithdrawalMoney, METHOD.POST, {
    disbName: disbName,
    disbNo: disbNo,
    applyUser: applyUser,
    applyUserId: applyUserId,
    accountNum: accountNum,
    tradeIds: tradeIds,
  });
}
// 佣金提现
export async function applyCashOut(params) {
  return request(ApplyCashOut, METHOD.POST, params);
}
// 获取分销商信息
export async function getUserData(id) {
  return request(userData, METHOD.GET, {
    id: id,
  });
}
// 提交分销商信息
export async function postUserData(params) {
  return request(postData, METHOD.PUT, params);
}
// 创建分销商
export async function addDis(params) {
  return request(createDis, METHOD.POST, params);
}
// 提交联系人信息
export async function postTelData(
  id,
  contactor,
  phone,
  fax,
  email,
  wx,
  qq,
  address
) {
  return request(postTel, METHOD.PUT, {
    id: id,
    contactor: contactor,
    phone: phone,
    fax: fax,
    email: email,
    wx: wx,
    qq: qq,
    address: address,
  });
}
// 获取银行数据
export async function getBanks() {
  return request(bankData, METHOD.GET, {
    skipCount: 0,
    maxResultCount: 9999,
    layout: "banks",
  });
}
// 上传图片
export async function uploader(files) {
  return request(upload, METHOD.POST, {
    files: files,
  });
}
// 获取图片
export async function getPhotos(sysRowId) {
  return request(getUpload, METHOD.GET, {
    sysRowId: sysRowId,
  });
}
// 获取订单
export async function getOrderList(skipCount, maxResultCount, memberId) {
  return request(getOrder, METHOD.GET, {
    skipCount,
    maxResultCount,
    memberId,
  });
}
// 获取分销商消费记录和总金额数
export async function getCountData(disNo, dateMode) {
  return request(getCount, METHOD.GET, {
    disNo: disNo,
    dateMode: dateMode,
  });
}
// 创建分销商消费记录和总金额数
export async function createMem(params) {
  return request(createMember, METHOD.POST, {
    params,
  });
}
// 创建消费记录月柱状图
export async function getHistory(disNo, year, month) {
  return request(getHistogram, METHOD.GET, {
    disNo: disNo,
    year: year,
    month: month,
  });
}
// 获取分销商名下会员分布
export async function getMemberData(DisNo) {
  return request(getMember, METHOD.GET, {
    DisNo,
  });
}
// 获取分销商
export async function getByDisNo(disNo) {
  return request(getDisNo, METHOD.GET, {
    disNo,
  });
}
// 获取分销商
export async function disGetData(disNo) {
  return request(disGetList, METHOD.GET, {
    disNo,
  });
}
// export async function disGetData(disbNO) {
//   return request( disGetList,METHOD.GET,{
//     disbNO
//   });
// }
// 冻结申请
export async function frozenData(id, reason) {
  return request(frozen, METHOD.POST, {
    id: id,
    reason: reason,
  });
}
// 拒绝申请
export async function denyData(id, reason) {
  return request(deny, METHOD.POST, {
    id: id,
    reason: reason,
  });
}
//修改密码
export async function updatePass(id, oldPassword, newPassword, confirmPsw) {
  return request(
    `${BASE_URL}/api/services/app/Edu_Distributor/updatePassword?id=${id}&oldPassword=${oldPassword}&newPassword=${newPassword}&confirmPsw=${confirmPsw}`,
    METHOD.PUT
  );
}
//忘记密码
export async function forgetPass(mobile, password) {
  return request(
    `${BASE_URL}/api/services/app/Edu_Distributor/ForgetPassword?mobile=${mobile}&password=${password}`,
    METHOD.POST,
    {}
  );
}
//获取邀请人名下的会员
export async function getMembers(disNo, skipCount, maxResultCount) {
  return request(getInviteMembers, METHOD.GET, {
    disNo,
    skipCount,
    maxResultCount,
  });
}
// 完善资质认证
export async function updateCert(
  id,
  legalPerson,
  entIdNum,
  bank,
  bankBranch,
  bankAccount,
  businesslicense
) {
  return request(updateCertificate, METHOD.PUT, {
    id: id,
    //, 法人
    legalPerson: legalPerson,
    //企业证件号
    entIdNum: entIdNum,
    // 收款银行
    bank: bank,
    //收款支行
    bankBranch: bankBranch,
    // 银行账号
    bankAccount: bankAccount,
    // 营业执照
    businesslicense: businesslicense,
  });
}
// 查询提现记录
export async function applyHistory(params) {
  return request(ApplyHistory, METHOD.GET, params);
}
// 查询提现记录
export async function delapp(id) {
  return request(delApplyHistory, METHOD.DELETE, {id});
}

export default { goodsList, goodsColumns };
